home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / strlibs.zip / STRNMOV.C < prev    next >
Text File  |  1993-01-04  |  901b  |  31 lines

  1.  
  2. /*  File   : strnmov.c
  3.     Author : Richard A. O'Keefe.
  4.     Updated: 20 April 1984
  5.     Defines: strnmov()
  6.  
  7.     strnmov(dst, src, n) moves up to n characters of  src  to  dst.   It
  8.     always  moves  exactly n characters to dst; if src is shorter than n
  9.     characters dst will be extended on the right with NULs, while if src
  10.     is longer than n characters dst will be a truncated version  of  src
  11.     and  will  not  have  a closing NUL.  The result is a pointer to the
  12.     first NUL in dst, or is dst+n if dst was truncated.
  13. */
  14.  
  15. char *strnmov(dst, src, n)
  16.     register char *dst, *src;
  17.     register int n;
  18.     {
  19.         while (--n >= 0) {
  20.             if (!(*dst++ = *src++))
  21.             {
  22.                 src = dst-1;
  23.                 while (--n >= 0) *dst++ = '\0';
  24.                 return src;
  25.             }
  26.         }
  27.         *dst = '\0';
  28.         return dst;
  29.     }
  30.  
  31.